const mysql=require('mysql');
const dbUtil=require('../util/DBUtil')

function select(){
  let sql ='select * from dept';
  return dbUtil.query(sql)
}
function query(dept_name,dept_address){
  let sql='select * from dept where dept_name=? and dept_address=?';
  let params=new Array();
  params.push(dept_name);
  params.push(dept_address);
  sql=mysql.format(sql,params);
  console.log('sql:%s',sql);
  return dbUtil.query(sql);
}

function add(organ){
  let sql='insert into dept(dept_name,dept_count,superior,isUsed,dept_address)values(?,?,?,?,?)';
  let params=new Array();
  params.push(organ.dept_name);
  params.push(organ.dept_count);
  params.push(organ.superior);
  params.push(organ.isUsed);
  params.push(organ.dept_address);
  sql=mysql.format(sql,params);
  console.log('sql:%s',sql);
  return dbUtil.query(sql);
}

function update(organ){
  let sql='update dept set dept_name=?,dept_count=?,superior=?,isUsed=?,dept_address=?where dept_id=?';
  let params=new Array();
  params.push(organ.dept_name);
  params.push(organ.dept_count);
  params.push(organ.superior);
  params.push(organ.isUsed);
  params.push(organ.dept_address);
  params.push(organ.dept_id);
  sql=mysql.format(sql,params);
  console.log('sql:%s',sql);
  return dbUtil.query(sql);
}
module.exports={
  select:select,
  query:query,
  add:add,
  update:update
}
